package com.sk.bilibili.view.fragment.member;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.main.dynamic.DynamicAdapter;
import com.sk.bilibili.bean.Dynamic;
import com.sk.bilibili.callBack.DynamicCallBack;
import com.sk.bilibili.model.fragment.member.DynamicModel;
import com.sk.bilibili.model.fragment.member.HomeModel;
import com.sk.bilibili.view.activity.DynamicActivity;
import com.sk.bilibili.view.activity.MemberActivity;
import com.sk.bilibili.view.activity.ThemActivity;
import com.sk.bilibili.view.activity.VideoSetActivity;
import com.sk.bilibili.view.fragment.BaseListFragment;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.util.List;

public class DynamicFragment extends BaseRefreshFragment<DynamicModel> implements DynamicCallBack {

    private Integer memberId;

    public DynamicFragment(Integer memberId) {
        this.memberId=memberId;
    }

    @Override
    public void onRefresh() {
        model.refreshDynamic(memberId);
    }

    @Override
    public void onBottom() {
        model.loadMore(memberId);
    }

    private DynamicAdapter dynamicAdapter;

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        dynamicAdapter = new DynamicAdapter(getContext(), this);
        adapter.addAdapter(dynamicAdapter);
    }

    @Override
    public void onMemberClick(Integer id) {
        MemberActivity.start(getContext(),id);
    }

    @Override
    public void onVideoSetClick(Integer id) {
        VideoSetActivity.start(getContext(),id);
    }

    @Override
    public void onThemClick(Integer id) {
        ThemActivity.start(getContext(),id);
    }

    @Override
    public void onForwardClick(int type, Integer targetId) {
        DynamicActivity.start(getContext(),type,targetId);
    }

    @Override
    public void onPraiseClick(int type, Integer targetId) {
        model.addPraise(type,targetId);
    }

    public void refreshSuccess(List<Dynamic> records) {
        dynamicAdapter.setData(records);
        cancelRefresh();
    }

    public void loadSuccess(List<Dynamic> records) {
        dynamicAdapter.addData(records);
    }

    public void praiseSuccess(Boolean aBoolean) {
        toast(aBoolean?"点赞成功":"已取消点赞");
    }

}